package com.nba.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.nba.util.DBUtil;
import com.nba.bean.Admin;
import com.nba.dao.AdminDao;

public class AdminDaoImpl implements AdminDao {

	JdbcTemplate jt = new JdbcTemplate(DBUtil.getDataSource());
	
	@Override
	public Admin selectAdmin(String adminName, String password) {
		String sql = "SELECT * FROM admin WHERE admin_name = ? AND admin_password = ?";
		List<Admin> list = jt.query(sql, new BeanPropertyRowMapper<Admin>(Admin.class),adminName,password);
		if(list.size() == 0) {
			return null;
		}else {
			return list.get(0);
		}
	}

	@Override
	public int insertAdmin(String adminName, String password) {
		String sql = "INSERT INTO admin(admin_name , admin_password) Value(?,?)";
		return jt.update(sql, adminName,password);
	}

	@Override
	public Admin selectAdmin(String adminName) {
		String sql = "SELECT * FROM admin WHERE admin_name = ?";
		List<Admin> list = jt.query(sql, new BeanPropertyRowMapper<Admin>(Admin.class),adminName);
		if(list.size() == 0) {
			return null;
		}else {
			return list.get(0);
		}
	}

}
